package cn.yemuysy.code.lingting.model;

import java.util.ArrayList;
import java.util.List;

/**
 * 敏感词匹配结果
 */
public class MatchResult {
    
    /**
     * 匹配的敏感词
     */
    private String word;
    
    /**
     * 在原文中的起始位置
     */
    private int startIndex;
    
    /**
     * 在原文中的结束位置
     */
    private int endIndex;
    
    /**
     * 匹配类型
     */
    private MatchType matchType;
    
    /**
     * 组合敏感词的组成部分（仅组合类型时有效）
     */
    private List<String> combinationParts;
    
    /**
     * 匹配类型枚举
     */
    public enum MatchType {
        NORMAL,      // 普通敏感词
        COMBINATION, // 组合敏感词
        PINYIN,      // 拼音敏感词
        PINYIN_COMBINATION // 拼音组合敏感词
    }
    
    public MatchResult() {
        this.combinationParts = new ArrayList<>();
    }
    
    public MatchResult(String word, int startIndex, int endIndex, MatchType matchType) {
        this();
        this.word = word;
        this.startIndex = startIndex;
        this.endIndex = endIndex;
        this.matchType = matchType;
    }
    
    /**
     * 添加组合敏感词的组成部分
     */
    public void addCombinationPart(String part) {
        this.combinationParts.add(part);
    }
    
    /**
     * 获取匹配长度
     */
    public int getLength() {
        return endIndex - startIndex + 1;
    }
    
    /**
     * 检查是否为组合敏感词
     */
    public boolean isCombination() {
        return matchType == MatchType.COMBINATION || matchType == MatchType.PINYIN_COMBINATION;
    }
    
    /**
     * 检查是否为拼音相关匹配
     */
    public boolean isPinyinMatch() {
        return matchType == MatchType.PINYIN || matchType == MatchType.PINYIN_COMBINATION;
    }
    
    // Getters and Setters
    public String getWord() {
        return word;
    }
    
    public void setWord(String word) {
        this.word = word;
    }
    
    public int getStartIndex() {
        return startIndex;
    }
    
    public void setStartIndex(int startIndex) {
        this.startIndex = startIndex;
    }
    
    public int getEndIndex() {
        return endIndex;
    }
    
    public void setEndIndex(int endIndex) {
        this.endIndex = endIndex;
    }
    
    public MatchType getMatchType() {
        return matchType;
    }
    
    public void setMatchType(MatchType matchType) {
        this.matchType = matchType;
    }
    
    public List<String> getCombinationParts() {
        return combinationParts;
    }
    
    public void setCombinationParts(List<String> combinationParts) {
        this.combinationParts = combinationParts;
    }
    
    @Override
    public String toString() {
        return "MatchResult{" +
                "word='" + word + '\'' +
                ", startIndex=" + startIndex +
                ", endIndex=" + endIndex +
                ", matchType=" + matchType +
                ", combinationParts=" + combinationParts +
                '}';
    }
} 